export function enum_all_methods(class_name) {
  console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> enter enum_all_methods");
  var InnerClass = Java.use(class_name);
  var all_methods = InnerClass.class.getDeclaredMethods();
  //console.log(all_methods)
  for (var i = 0; i < all_methods.length; i++) {
    var method = all_methods[i];
    //console.log(method);
    var substring = method
      .toString()
      .substr(method.toString().indexOf(class_name) + class_name.length + 1);
    var finalMethodString = substring.substr(0, substring.indexOf("("));
    // 打印所有方法名
    // console.log(finalMethodString);
    console.log(method)
    // //批量hook返回true
    // InnerClass[finalMethodString].implementation = function () {
    //   return true;
    // };
  }
}

export function enum_all_fields(class_name) {
  console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> enter enum_all_fields");
  var InnerClass = Java.use(class_name);
  var all_fields = InnerClass.class.getDeclaredFields();
  for (var i = 0; i < all_fields.length; i++) {
    var field = all_fields[i];
    console.log(field);
  }
}

export function enum_obj_fields(clazz) {
  // let class_name = obj.$className
  // let clazz = Java.use(class_name);
  let arr = clazz.class.getDeclaredFields().map((field: any) => {
    const fieldName: string = field.getName();
    const fieldInstance = clazz.class.getDeclaredField(fieldName);
    fieldInstance.setAccessible(true);

    let fieldValue = fieldInstance.get(clazz);
    console.log(fieldName, fieldValue, fieldInstance);

    // Cast a string if possible
    if (fieldValue) {
      fieldValue = fieldValue.toString();
    }

    return {
      name: fieldName,
      value: fieldValue,
    };
  });
  return JSON.stringify(arr);
}

export function enum_obj_fields_by_choose(class_name) {
  console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> enter enum_obj_fields");
  Java.choose(class_name,{
    onMatch: function(instance){
      console.log('instance found',instance)
      // instance.secret()
    },
    onComplete: function(){
      console.log('search Complete')
    }
  })
}
